import 'package:flutter/material.dart';
import 'package:flutter_basic_learning/widgets/MineButton.dart';
import 'package:get/get.dart';

import '../widgets/CommonHeader.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key, required this.title});

  final String title;

  @override
  State<StatefulWidget> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  Widget body() {
    Widget body = Column(
        //设置纵向居中
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          MineButton(
              buttonName: 'Getx 弹窗',
              onPress: () {
                Get.defaultDialog(
                    title: '提示',
                    content: const Text('hello'),
                    textConfirm: '确定',
                    onConfirm: () {
                      print('Confirm');
                      Get.back();
                    },
                    textCancel: '取消',
                    onCancel: () {
                      print('Cancel');
                    });
              }),
          MineButton(
              buttonName: 'Getx SnackBar',
              onPress: () => {
                    Get.snackbar('title', 'message',
                        duration: const Duration(seconds: 1))
                  }),
        ]);
    // 设置宽度自适应
    body = SizedBox.expand(child: body);
    return body;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const PreferredSize(
          preferredSize: Size.fromHeight(50),
          child: CommonHeader(
            title: 'HomePage',
            showBackIcon: false,
          )),
      body: body(),
    );
  }
}
